//author: create by SunJH
//时间: 2021/11/29 0029
//邮箱: 965989158@qq.com
//描述: sliver组件测试文件

import 'package:card_swiper/card_swiper.dart';
import 'package:flutter/material.dart';
import 'package:flutter_app/counter/sliver_controller.dart';
import 'package:get/get.dart';

class SliverViewTest extends GetView<SliverController> {
  const SliverViewTest({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    Get.put<SliverController>(SliverController());
    return Scaffold(body: createNestWidget());
  }

  createTopInfoWidget() {
    return SliverToBoxAdapter(
      child: Stack(
        children: [
          Container(
            padding: const EdgeInsets.only(right: 30),
            alignment: Alignment.centerRight,
            child: Image.network(
              controller.topWeatherPath.value,
              width: 40,
              height: 40,
            ),
          ),
          Padding(
            padding: const EdgeInsets.only(left: 20),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: const [
                Text(
                  "学校管理员,上午好",
                  style: TextStyle(fontSize: 18),
                ),
                Text(
                  "2021年11月26日，星期五",
                  style: TextStyle(fontSize: 15),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }

  createSliverTestPage() {
    return CustomScrollView(slivers: <Widget>[
      SliverAppBar(
        leading: Text(""),
        pinned: true,
        floating: true,
        snap: true,
        expandedHeight: 500.0,
        flexibleSpace: FlexibleSpaceBar(
          background: Image.network(
            'http://img.haote.com/upload/20180918/2018091815372344164.jpg',
            fit: BoxFit.cover,
          ),
        ),
      ),
      SliverList(
        delegate: SliverChildBuilderDelegate((content, index) {
          return Container(
            height: 65,
            color: Colors.primaries[index % Colors.primaries.length],
          );
        }, childCount: 5),
      ),
      SliverGrid(
        gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
            crossAxisCount: 3, crossAxisSpacing: 5, mainAxisSpacing: 3),
        delegate: SliverChildBuilderDelegate((BuildContext context, int index) {
          return Container(
            color: Colors.primaries[index % Colors.primaries.length],
          );
        }, childCount: 20),
      )
    ]);
  }

  bannerWidget() {
    return SliverToBoxAdapter(
      child: SizedBox(
        height: 120,
        child: Swiper(
          itemCount: controller.bannerItems.length,
          pagination:  const SwiperPagination(),
          controller: SwiperController(),
          loop: true,
          autoplay: true,
          itemBuilder: (context, index) {
            return Image.network(controller.bannerItems.value[index],fit:BoxFit.cover,);
          },
        ),
      ),
    );
  }
  createNestWidget() {
    return CustomScrollView(
      slivers: [
        SliverToBoxAdapter(
          child: Container(
            height: 100,
          ),
        ),
        createTopInfoWidget(),
        bannerWidget(),
        createListView(),
      ],
    );
  }

  createListView() {
    return SliverList(delegate: SliverChildListDelegate(
      controller.infos.value.map((e) => Container(
          height: 120,
          alignment: Alignment.center,
          child: Text(e,style: TextStyle(fontSize: 20),))).toList()
    ),
    );
  }
}
